<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=1200, initial-scale=1.0">
    <title>事件委托示例</title>
    <style>
        .box {
            background-color:coral;
            width: 50px;
        }
    </style>
</head>
<body>
    <ul id='list'>
        <li>Java</li>
        <li>JavaScript</li>
        <li>Python</li>
        <li>C#</li>
    </ul>

    <script>
        // mouseover/mouseout
        const oList = document.querySelector('#list')

        oList.addEventListener('mouseover', (e)=> {
            if (e.target != e.currentTarget) {
                e.target.classList.add('box')
            }
        })

        oList.addEventListener('mouseout', (e) => {
            e.target.classList.remove('box')
        })

    </script>
</body>
</html>